package zz.app.ustbgsmanager.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Locale;
import java.util.Objects;

import zz.app.ustbgsmanager.R;
import zz.app.ustbgsmanager.adapters.CourseRecyclerViewAdapter;
import zz.app.ustbgsmanager.beans.querycourse.CourseInfo;
import zz.app.ustbgsmanager.other.ShortHorizontalDividerItemDecoration;

public class CourseFragment extends Fragment {
    ArrayList<CourseInfo> courseInfos;
    RecyclerView recyclerView;
    LinearLayout llHint;
    CourseRecyclerViewAdapter adapter;
    private String day;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.layout_course_fragment,container,false);
        llHint=view.findViewById(R.id.llHint);
        recyclerView=view.findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL,false));
        recyclerView.addItemDecoration(new ShortHorizontalDividerItemDecoration(getContext()));
        adapter=new CourseRecyclerViewAdapter(getContext());
        adapter.setCourseInfos(courseInfos);
        TextView textView= (TextView) llHint.getChildAt(0);
        textView.setText(String.format(Locale.getDefault(),"你%s好像没有课",day));
        if(courseInfos.size()>0){
            llHint.setVisibility(View.GONE);
        }
        recyclerView.setAdapter(adapter);
        return view;
    }

    public void setCourseInfos(ArrayList<CourseInfo> courseInfos) {
        this.courseInfos=courseInfos;
    }

    public void setDay(String day) {
        this.day=day;
    }
}
